package PolladminFunc;

import java.sql.ResultSet;
import java.util.ArrayList;

import bean.Poll;


import utils.DBConn;

public class PollDAO extends DBConn {

	private ResultSet rs;
	public void add(Poll poll){
		try{
			super.getConnection();
			String sql="INSERT INTO Poll(Name,Latitude,Longitude,Description,CreatorName) VALUES (?,?,?,?,?)";
			ps=conn.prepareStatement(sql);
			ps.setString(1, poll.getName());
			ps.setString(2, poll.getLatitude());
			ps.setString(3, poll.getLongitude());
			ps.setString(4, poll.getDescription());
			ps.setString(5, poll.getCreator());
			ps.executeUpdate();
		}catch(Exception e){e.printStackTrace();}
	}
	
	public ArrayList<Poll> show(){
		ArrayList<Poll> pollList=new ArrayList<Poll>();
		super.getConnection();
		String sql="SELECT ID, Name, Description, CreateTime, Latitude, Longitude, CreatorName FROM Poll";
		try{
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery(sql);
			Poll poll=null;
			while(rs.next()){
				poll=new Poll();
				poll.setId(rs.getInt("ID"));
				poll.setName(rs.getString("Name"));
				poll.setLatitude(rs.getString("Latitude"));
				poll.setLongitude(rs.getString("Longitude"));
				poll.setCreator(rs.getString("CreatorName"));
				poll.setCreatetime(rs.getDate("CreateTime"));
				poll.setDescription(rs.getString("Description"));
				pollList.add(poll);
			}
		}catch(Exception e){e.printStackTrace();}
		return pollList;
	}
	
	public void delete(Poll poll){
		try{
			super.getConnection();
			String sql="";
			ps=conn.prepareStatement(sql);
		}catch(Exception e){e.printStackTrace();}
	}
	
	public void update(Poll poll){
		try{
			super.getConnection();
			String sql="";
			ps=conn.prepareStatement(sql);
		}catch(Exception e){e.printStackTrace();}
	}
}
